/****************************************************************************
*
* Description: Base exception
* Created at: 19.11.06 21:43:08 UTC
*
* $Revision$
*
****************************************************************************/
#pragma once

#if !defined(__common_exception_h__)
#define __common_exception_h__

#include <string>
#include <sstream>
#include <stdexcept>

namespace common {

class basic_error
{
public:
    basic_error(const char* msg, const char* module, int line)
    	: msg_(msg)
    	, module_(module)
    	, line_(line)
    {}

    basic_error(const basic_error& r)
    {
        msg_.assign(r.msg_);
        module_.assign(r.module_);
        line_ = r.line_;
    }

    virtual std::string what() const
    {
        std::ostringstream e;
        e << "[" << module_.c_str() << ":" << line_ << "]: " << msg_.c_str();
        return e.str();
    }

private:
    std::string msg_;
    std::string module_;
    int         line_;
};

#define THROW(x, msg) \
    throw x(msg, __FILE__, __LINE__)

#define DEFINE_NEW_ERROR(name) \
	class name : public common::basic_error { \
    public: \
        name(const char* msg, const char* module, int line) : \
            common::basic_error(msg, module, line) \
        {} \
    }

DEFINE_NEW_ERROR(not_implemented);

} /* End of common  */

#endif  /* End of __common_exception_h__.  */
